import Vue from 'vue'
import Router from 'vue-router'

import Index from '@/components/index'
import ProductSum from '@/components/productSum'
import ProductDet from '@/components/productDet'
import AboutUs from '@/components/aboutUs'
import Recruit from '@/components/recruit'
import ProjectSum from '@/components/projectSum'
import ProjectDet from '@/components/projectDet'
import News from '@/components/news'
import ComNews from '@/components/newsFile/comNews'
import RealNews from '@/components/newsFile/realNews'
import MediaNews from '@/components/newsFile/mediaNews'
import Login from '@/components/login'
import Ctrade from '@/components/ctrade'
import Cintr from '@/components/ctrade/cintr'
import Cproc from '@/components/ctrade/cproc'

Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'Index',
      component: Index
    },
    {
      path: '/productSum',
      name: 'ProductSum',
      component: ProductSum
    },
    {
      path: '/aboutUs',
      name: 'AboutUs',
      component: AboutUs
    },
    {
      path: '/recruit',
      name: 'Recruit',
      component: Recruit
    },
    {
      path: '/projectSum',
      name: 'ProjectSum',
      component: ProjectSum
    },
    {
      path: '/login',
      meta: {
        //meta元素，添加该字段，表示进入这个路由是需要登录的
          requireAuth: true,
      },
      component: Login,
    },
    {
      path: '/news',
      name: 'News',
      component: News,
      children: [
        {
          path: 'comNews',
          name: 'ComNews',
          component: ComNews
        },
        {
          path: 'realNews',
          name: 'RealNews',
          component: RealNews
        },
        {
          path: 'mediaNews',
          name: 'MediaNews',
          component: MediaNews
        }
      ]
    },
    {
      path: '/ctrade',
      name: 'Ctrade',
      component: Ctrade,
      children: [
        {
          path: 'cintr',
          name: 'Cintr',
          component: Cintr
        },
        {
          path: 'cproc',
          name: 'Cproc',
          component: Cproc
        }
      ]
    },
    {
      path: '/:pro',
      name: 'ProjectDet',
      component: ProjectDet
    },
    {
      path: '/:item',
      name: 'ProductDet',
      component: ProductDet
    }
  ],
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})
